package com.luocj.muke.common.dialog.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.luocj.muke.common.R;


public class MDialog extends Dialog {
    private static final String LAYOUT = "layout";
    private Context mContext;

    @LayoutRes
    private int layoutId;
    private View inflate;

    public View getInflate() {
        return inflate;
    }

    public void setInflate(View inflate) {
        this.inflate = inflate;
    }

    public static MDialog init(Context context){
        return new MDialog(context);
    }

    public int getLayoutId() {
        return layoutId;
    }

    public MDialog setLayoutId(int layoutId) {
        this.layoutId = layoutId;
        return this;
    }

    public MDialog(Context context) {
        super(context);
        mContext = context;

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        inflate = LayoutInflater.from(mContext).inflate(getLayoutId(), null);
        setContentView(inflate);
        Window dialogWindow = this.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = (int) ((int) mContext.getResources().getDisplayMetrics().widthPixels *0.8);
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        dialogWindow.setGravity(Gravity.CENTER);
        dialogWindow.setBackgroundDrawable(new ColorDrawable(0));
        dialogWindow.setAttributes(lp);
    }
}
